FROM node:22-alpine AS daytona

# Install nodejs
RUN apk --update add --no-cache nodejs=22.16.0-r2 npm bash curl
RUN npm install -g corepack && corepack enable

WORKDIR /daytona

COPY . .

ARG VERSION=0.0.1
ENV VERSION=${VERSION}

RUN yarn

RUN yarn nx build api --configuration=production --nxBail=true && \
  VITE_BASE_API_URL=%DAYTONA_BASE_API_URL% yarn nx build dashboard --configuration=production --nxBail=true

ENV NODE_ENV=production

ENV PORT=3000

ENV DB_HOST=db
ENV DB_PORT=5432
ENV DB_USERNAME=user
ENV DB_PASSWORD=pass
ENV DB_DATABASE=daytona

ENV REDIS_HOST=redis
ENV REDIS_PORT=6379

ENV OIDC_CLIENT_ID=daytona
ENV OIDC_ISSUER_BASE_URL=http://dex:5556/dex
ENV PUBLIC_OIDC_DOMAIN=http://localhost:5556/dex
ENV OIDC_AUDIENCE=daytona

ENV OIDC_MANAGEMENT_API_ENABLED=
ENV OIDC_MANAGEMENT_API_CLIENT_ID=
ENV OIDC_MANAGEMENT_API_CLIENT_SECRET=
ENV OIDC_MANAGEMENT_API_AUDIENCE=

ENV DEFAULT_SNAPSHOT=daytonaio/sandbox:0.5.0
ENV DASHBOARD_URL=http://localhost:3000/dashboard
ENV DASHBOARD_BASE_API_URL=http://localhost:3000

ENV POSTHOG_API_KEY=phc_bYtEsdMDrNLydXPD4tufkBrHKgfO2zbycM30LOowYNv
ENV POSTHOG_HOST=https://d18ag4dodbta3l.cloudfront.net
ENV POSTHOG_ENVIRONMENT=local

ENV TRANSIENT_REGISTRY_URL=http://registry:6000
ENV TRANSIENT_REGISTRY_ADMIN=admin
ENV TRANSIENT_REGISTRY_PASSWORD=password
ENV TRANSIENT_REGISTRY_PROJECT_ID=daytona

ENV INTERNAL_REGISTRY_URL=http://registry:6000
ENV INTERNAL_REGISTRY_ADMIN=admin
ENV INTERNAL_REGISTRY_PASSWORD=password
ENV INTERNAL_REGISTRY_PROJECT_ID=daytona

ENV SMTP_HOST=maildev
ENV SMTP_PORT=1025
ENV SMTP_USER=
ENV SMTP_PASSWORD=
ENV SMTP_SECURE=
ENV SMTP_EMAIL_FROM="Daytona Team <no-reply@daytona.io>"

ENV S3_ENDPOINT=http://minio:9000
ENV S3_STS_ENDPOINT=http://minio:9000/minio/v1/assume-role
ENV S3_REGION=us-east-1
ENV S3_ACCESS_KEY=minioadmin
ENV S3_SECRET_KEY=minioadmin
ENV S3_DEFAULT_BUCKET=daytona
ENV S3_ACCOUNT_ID=/
ENV S3_ROLE_NAME=/

ENV ENVIRONMENT=dev

ENV MAX_AUTO_ARCHIVE_INTERVAL=43200

ENV MAINTENANCE_MODE=false

ENV PROXY_DOMAIN=proxy.localhost:4000
ENV PROXY_PROTOCOL=http
ENV PROXY_API_KEY=super_secret_key
ENV PROXY_TEMPLATE_URL=http://{{PORT}}-{{sandboxId}}.proxy.localhost:4000

ENV DEFAULT_RUNNER_DOMAIN=runner:3003
ENV DEFAULT_RUNNER_API_URL=http://runner:3003
ENV DEFAULT_RUNNER_PROXY_URL=http://runner:3003
ENV DEFAULT_RUNNER_API_KEY=secret_api_token
ENV DEFAULT_RUNNER_CPU=4
ENV DEFAULT_RUNNER_MEMORY=8
ENV DEFAULT_RUNNER_DISK=50
ENV DEFAULT_RUNNER_GPU=0
ENV DEFAULT_RUNNER_GPU_TYPE=none
ENV DEFAULT_RUNNER_CAPACITY=100
ENV DEFAULT_RUNNER_CLASS=small

ENV DEFAULT_REGION_ID=us
ENV DEFAULT_REGION_NAME=us
ENV DEFAULT_REGION_ENFORCE_QUOTAS=false

ENV DEFAULT_ORG_QUOTA_TOTAL_CPU_QUOTA=10000
ENV DEFAULT_ORG_QUOTA_TOTAL_MEMORY_QUOTA=10000
ENV DEFAULT_ORG_QUOTA_TOTAL_DISK_QUOTA=100000
ENV DEFAULT_ORG_QUOTA_MAX_CPU_PER_SANDBOX=100
ENV DEFAULT_ORG_QUOTA_MAX_MEMORY_PER_SANDBOX=100
ENV DEFAULT_ORG_QUOTA_MAX_DISK_PER_SANDBOX=1000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D=10

ENV SKIP_USER_EMAIL_VERIFICATION=true

ENV RUN_MIGRATIONS=true

HEALTHCHECK CMD [ "curl", "-f", "http://localhost:3000/api/config" ]

ENTRYPOINT ["node", "dist/apps/api/main.js"]
